package com.runen.wnhz.runen.ui.adapter.puadapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.data.entity.MyCollection;
import com.runen.wnhz.runen.ui.activity.major.CourseDetailsActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyCollectionRecyclerAdapter extends RecyclerView.Adapter<com.runen.wnhz.runen.ui.adapter.puadapter.MyCollectionRecyclerAdapter.ViewHolder> {

    private List<MyCollection.DataBean.ListBean> listBeans;

    private Context context;

    public MyCollectionRecyclerAdapter(List<MyCollection.DataBean.ListBean> listBeans, Context context) {
        this.listBeans = listBeans;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.my_collection_item_layout,null);
        com.runen.wnhz.runen.ui.adapter.puadapter.MyCollectionRecyclerAdapter.ViewHolder viewHolder = new com.runen.wnhz.runen.ui.adapter.puadapter.MyCollectionRecyclerAdapter.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final MyCollection.DataBean.ListBean listBean = listBeans.get(position);
        Glide.with(context).load(listBean.getPic()).into(holder.image_collectionPic);
        holder.text_collectionName.setText(listBean.getTitle());
        holder.text_collectionNumber.setText(listBean.getLearn_mans().concat("人学习"));
        holder.text_collectionPrice.setText("￥".concat(listBean.getPrice()));
        holder.relative_myCollection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(context, CourseDetailsActivity.class);
                intent.putExtra("lid",listBean.getLid());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if(listBeans != null){
            return listBeans.size();
        }else {
            return 0;
        }
    }


    class ViewHolder extends RecyclerView.ViewHolder{

        @BindView(R.id.image_collectionPic)
        ImageView image_collectionPic;
        @BindView(R.id.text_collectionName)
        TextView text_collectionName;
        @BindView(R.id.text_collectionNumber)
        TextView text_collectionNumber;
        @BindView(R.id.text_collectionPrice)
        TextView text_collectionPrice;
        @BindView(R.id.relative_myCollection)
        RelativeLayout relative_myCollection;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
